package com.itheima.project.face.impl;

import com.itheima.project.constant.security.ResourceCacheConstant;
import com.itheima.project.core.enums.security.MenusEnum;
import com.itheima.project.exception.ProjectException;
import com.itheima.project.face.MenusFace;
import com.itheima.project.service.IMenusService;
import com.itheima.project.utils.ExceptionsUtil;
import com.itheima.project.vo.security.MenuVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName MenusFaceImpl.java
 * @Description 菜单服务实现
 */
@Slf4j
@Component
public class MenusFaceImpl implements MenusFace {

    @Autowired
    IMenusService menusService;

    @Override
    @Cacheable(value = ResourceCacheConstant.MENU,key = "#systemCode")
    public List<MenuVo> findMenusBySystemCode(String systemCode)throws ProjectException {
        try {
            return menusService.findMenusBySystemCode(systemCode);
        } catch (Exception e) {
            log.error("查询附件列表异常：{}", ExceptionsUtil.getStackTraceAsString(e));
            throw new ProjectException(MenusEnum.PAGE_FAIL);
        }
    }
}
